package interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SomeInterceptor implements HandlerInterceptor{
	
	/**
	 * DispatcherServlet在收到请求后,会先调用preHandle方法.
	 * 如果该方法的返回值是true,则继续向后调用;如果返回值是false,
	 * 则中断请求.
	 * 注:
	 * DispatcherServlet,拦截器,以及处理器(controller)会共享
	 * 同一个request,response
	 *  arg2:Controller的方法对象
	 * 
	 */
	public boolean preHandle(
			HttpServletRequest request, 
			HttpServletResponse response, 
			Object arg2)
			throws Exception {
		
		System.out.println("preHandle()");
		return true;
	}

	
	/**
	 * Controller的方法已经执行完毕,
	 * 准备将ModelAndView返回给DispatcherServlet之前,
	 * 执行poetHandle()方法.可以在该方法里面修改
	 * 处理结果(ModelAndView)
	 */
	
	public void postHandle(
			HttpServletRequest request, 
			HttpServletResponse response, 
			Object handler,
			ModelAndView modelAndView) throws Exception {

		System.out.println("ModelAndView()");
		
		
	}

	
	/**
	 * 最后执行的方法
	 * 参数ex:是处理器(Controller)抛出的异常
	 */
	public void afterCompletion(
			HttpServletRequest request, 
			HttpServletResponse response, 
			Object handler, 
			Exception ex)
			throws Exception {

		System.out.println("afterCompletion");
		
	}
	


}
















